﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DAL.DCollector;
using System.Data.SqlClient;


namespace BOL
{
    public class ProductManager
    {


        public static ProductManager Instance = new ProductManager();

    
        public DataTable GetTablePagingIndex(int n, int pagesize , int currentPage)
        {
            
            
            int pageStart=5*(int)(currentPage/5);
            int pageEnd = 5 + pageStart;

            if (pageStart == 0)
            {
                pageStart = 1;
                pageEnd = 5;
            }
            DataTable TablePagingIndex = new DataTable();
            TablePagingIndex.Columns.Add("PageIndex", typeof(int));
            TablePagingIndex.Columns.Add("PageCurent", typeof(string));

            int numofpageindex = (n % pagesize == 0 ? (n / pagesize) : (n / pagesize) + 1);
            if ((numofpageindex - pageStart) < 5) pageEnd = numofpageindex;

          

            for (int i = pageStart; i <= pageEnd; i++)
            {
                if(i==currentPage)
                    TablePagingIndex.Rows.Add(i, "currentPage");
                else
                    TablePagingIndex.Rows.Add(i, "");
            }
            return TablePagingIndex;
        }

        // by duyen :x . viet ham phan trang  lay tu thu tuc 
        public DataTable GetListProductsPaging(string table, string procedurename, int currentpage, int sizepage, int idcate, string orderColumn,string sort)
        {
            SqlParameter[] p = new SqlParameter[6];
            p[0] = new SqlParameter("@currentpage", currentpage);
            p[1] = new SqlParameter("@sizepage", sizepage);
            p[2] = new SqlParameter("@table", table);
            p[3] = new SqlParameter("@idcate", idcate);
            p[4] = new SqlParameter("@column", orderColumn);
            p[5] = new SqlParameter("@sort", sort);
            return DAL.DatabaseManager.SqlServerInstance.CallStoredProcedure(procedurename, p, true);


        }
        public DataTable GetListProductsPaging(string table, string procedurename, int currentpage, int sizepage, string content, string orderColumn, string sort,string  sortcolumn)
        {
            SqlParameter[] p = new SqlParameter[7];
            p[0] = new SqlParameter("@currentpage", currentpage);
            p[1] = new SqlParameter("@sizepage", sizepage);
            p[2] = new SqlParameter("@table", table);
            p[3] = new SqlParameter("@content", content);
            p[4] = new SqlParameter("@column", orderColumn);
            p[5] = new SqlParameter("@sort", sort);
            p[6] = new SqlParameter("@sortcolumn", sortcolumn);
            return DAL.DatabaseManager.SqlServerInstance.CallStoredProcedure(procedurename, p, true);


        }


        public DataTable GetListNewsPaging(string table, string procedurename, int currentpage, int sizepage,  string orderColumn, string sort)
        {
            SqlParameter[] p = new SqlParameter[5];
            p[0] = new SqlParameter("@currentpage", currentpage);
            p[1] = new SqlParameter("@sizepage", sizepage);
            p[2] = new SqlParameter("@table", table);
            p[3] = new SqlParameter("@column", orderColumn);
            p[4] = new SqlParameter("@sort", sort);
            return DAL.DatabaseManager.SqlServerInstance.CallStoredProcedure(procedurename, p, true);


        }

    }
}
